import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { fileURLToPath, URL } from 'node:url'

// https://vitejs.dev/config/
export default defineConfig({
  // 确保docx库在浏览器环境中正常工作
  define: {
    'process.env': {}
  },
  optimizeDeps: {
    include: ['docx', 'file-saver']
  },
  plugins: [vue()],
  server: {
    port: 3000,
    open: true
  },
  build: {
    outDir: 'dist',
    assetsDir: 'assets',
    sourcemap: false,
    rollupOptions: {
      output: {
        manualChunks(id) {
          if (id.includes('node_modules')) {
            return id.toString().split('node_modules/')[1].split('/')[0].toString();
          }
        }
      }
    }
  },
  css: {
    preprocessorOptions: {
      css: {
        additionalData: `
          :root {
            --primary-color: #3498db;
            --secondary-color: #2980b9;
            --success-color: #27ae60;
            --error-color: #e74c3c;
            --text-color: #333;
            --bg-color: #f5f5f5;
            --white: #fff;
            --border-color: #ddd;
          }
        `
      }
    }
  }
})